import { RouteListState } from '@/types/pinia'
import { defineStore } from 'pinia'
import { getRouteList } from '@/api/system/menu/index'
import { Menu } from '@/api/system/menu/types'

/**
 * 路由列表
 * @methods setRouteList 设置路由数据
 * @methods setColumnsMenuHover 设置分栏布局菜单鼠标移入 boolean
 * @methods setColumnsNavHover 设置分栏布局最左侧导航鼠标移入 boolean
 */
export const useRouteStore = defineStore('routeStore', {
    state: (): RouteListState => ({
        routeList: [],
        isColumnsMenuHover: false,
        isColumnsNavHover: false,
    }),
    actions: {
        async setRouteList(data: Array<Menu.Route>) {
            this.routeList = data
        },
        async setColumnsMenuHover(bool: boolean) {
            this.isColumnsMenuHover = bool
        },
        async setColumnsNavHover(bool: boolean) {
            this.isColumnsNavHover = bool
        },

        async getRoutes() {
            return new Promise((resolve, reject) => {
                getRouteList()
                    .then((resp) => {
                        resolve(resp)
                    })
                    .catch((err) => {
                        reject(err)
                    })
            })
        },

        /**
         * 生成路由地址
         */
        // async generateRoutes() {
        //     const routes = await this.getRoutes()
        // },
    },
})
